package com.library.controller;

import com.library.dao.NoticeDao;
import com.library.dao.impl.NoticeDaoImpl;
import com.library.entity.Notice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/welcome")
public class WelcomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取公告列表
        NoticeDao noticeDao = new NoticeDaoImpl();
        List<Notice> noticeList = noticeDao.getAllNotices();
        
        // 将公告列表存入request域
        request.setAttribute("noticeList", noticeList);
        
        // 转发到欢迎页面
        request.getRequestDispatcher("/pages/welcome.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}